package cn.wolfcode.trip.app.interceptor;

import cn.wolfcode.trip.app.util.UserContext;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CheckLoginInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //从session中拿出当前用户
        if(UserContext.getCurrentUser()==null){
            //拿不到的话就证明没有登录，那么就重新跳转到登录界面
            response.sendRedirect("/login.html");
            return false ;
        }
        //能执行到这里的话就证明有进行登录
        return true ;
    }
}
